package com.aigou.admin.service.impl;

import com.aigou.admin.dao.OrderDao;
import com.aigou.admin.dao.impl.OrderDaoImpl;
import com.aigou.admin.entity.Order;
import com.aigou.admin.entity.PageEntity;
import com.aigou.admin.service.OrderService;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.List;


@Service
@AllArgsConstructor
public class OrderServiceImpl implements OrderService {

    private OrderDao orderDao;

    @Override
    public List<Order> findAll() {
        return orderDao.selectAll();
    }

    @Override
    public Order findById(String id) {
        return orderDao.selectById(id);
    }

    @Override
    public Boolean save(Order order) {
        return orderDao.insert(order);
    }

    @Override
    public Boolean update(Order order) {
        return orderDao.update(order);
    }

    @Override
    public Boolean remove(String id) {
        return orderDao.delete(id);
    }

    @Override
    public PageEntity<Order> findOrderByPage(Integer currentPage, Integer pageSize) {
        Integer total = orderDao.selectOrderCount();
        List<Order> orders = orderDao.selectOrderByLimit((currentPage - 1) * pageSize, pageSize);
        PageEntity<Order> pageEntity = new PageEntity<>();
        pageEntity.setTotal(total);
        pageEntity.setPageSize(pageSize);
        pageEntity.setCurrent(currentPage);
        pageEntity.setRecords(orders);
        return pageEntity;
    }
}
